#include "linklist.h"

LinkList::LinkList()
{
    this->next=nullptr;
    this->length=0;
}
unsigned int LinkList::getLength()
{
    return this->length;
}
void LinkList::add(double pos1,double pos2)
{
    Record *p=new Record();
    if(p)
    {
        p->x=pos1;
        p->y=pos2;
        p->next=this->next;
        this->next=p;
        this->length++;
    }
    if(length<=3)
    {
        if(this->length==1)
        {
            this->origin[0]=p->x;
            this->origin[1]=p->y;
        }
        else if(this->length==2)
        {
            this->x[0]=p->x;
            this->x[1]=p->y;
        }
        else if(this->length==3)
        {
            this->y[0]=p->x;
            this->y[1]=p->y;
        }
    }
}
void LinkList::del(double& temp1,double& temp2)
{
    if(this->length)
    {
        Record *p;
        p=this->next;
        this->length--;
        temp1=p->x;
        temp2=p->y;
        this->next=p->next;
        delete p;
    }
}
